package com.ejd.web.vo.genl;

import java.util.List;


import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.SelectItem;


import com.ejd.service.IMaterialService;
import com.ejd.service.IPatternService;
import com.ejd.utils.MessageFactory;
import com.ejd.utils.SpringFacesUtil;
import com.ejd.web.bo.impl.Material;
import com.ejd.web.bo.impl.Pattern;
import com.ejd.web.constant.EjdConstants;
import com.ejd.web.constant.SpringBeanConstants;

@ManagedBean(name="existPattern")
@SessionScoped
public class ExistPatternBean implements java.io.Serializable {

	private SelectItem[] patternItems;


	public SelectItem[] getPatternItems() {
		return patternItems;
	}


	public void setPatternItems(SelectItem[] patternItems) {
		this.patternItems = patternItems;
	}


	public ExistPatternBean() {
		
		IPatternService<Pattern,Long> patternService = (IPatternService<Pattern,Long>)SpringFacesUtil.getSpringBean(SpringBeanConstants.PATTERN_SERVICE_BEAN_NAME);
		patternService.setEntityClass(Pattern.class);
		patternService.setPKClass(Long.class);
		List<Pattern> patterns = patternService.getAll();
		SelectItem[] tempPatternItems = new SelectItem[patterns.size()];
		if (null != patterns && !(patterns.isEmpty())) {
			for (int i=0; i< tempPatternItems.length; i++) {
				Pattern pattern = (Pattern) patterns.get(i);
				String materialNameN18 = MessageFactory.getMessage(EjdConstants.USER_BUNDLE_NAME,pattern.getPatternName(), FacesMessage.SEVERITY_ERROR).getDetail();
				tempPatternItems[i] = new SelectItem(pattern.getPatternCode(),materialNameN18);
			}
		}
		this.setPatternItems(tempPatternItems);
	}
}
